package com.example.test;

import com.mt.sdk.ble.MTBLEManager;
import com.mt.sdk.ble.base.BLEBase;
import com.mt.sdk.ble.model.ErroCode;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		initView();
		
		initBLE();
	}
	
	private Button connect_btn;
	private Button disconnect_btn;
	private void initView(){
		connect_btn = (Button) findViewById(R.id.connect_btn);
		disconnect_btn = (Button) findViewById(R.id.disconnect_btn);
		
		connect_btn.setOnClickListener(myOnClickListener);
		disconnect_btn.setOnClickListener(myOnClickListener);
	}
	
	private OnClickListener myOnClickListener = new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			if(v == connect_btn){
				mble.connect("88:C2:55:11:64:1D", 2, false);
			}else{
				mble.disConnect();
			}
			
		}
	};
	
	// 初始化ble
	private MTBLEManager manger;
	private BLEBase mble;
	private void initBLE(){
		manger = MTBLEManager.getInstance(getApplicationContext());
		mble = new BLEBase(getApplicationContext(), manger){

			@Override
			protected void onBaseConnect(ErroCode errocode) {
				super.onBaseConnect(errocode);
				System.out.println("onBaseConnect->"+errocode.toString());
			}

			@Override
			protected void onDisConnect(ErroCode errocode) {
				super.onDisConnect(errocode);
				System.out.println("onDisConnect->"+errocode.toString());
			}

			@Override
			protected void onManualDisConnect(ErroCode errocode) {
				super.onManualDisConnect(errocode);
				System.out.println("onManualDisConnect->"+errocode.toString());
			}
			
		};
	}
	
}
